package com.zmj.sy.mom.srv.aps.mapper;

import com.zmj.sy.mom.srv.aps.bean.entity.order.ImportErpBom;
import com.zmj.sy.mom.srv.aps.bean.vo.order.OrderExternalBomResVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ImportErpBomMapper extends SyMapper<ImportErpBom> {


    @Select(" SELECT bom.id, bom.order_code, bom.material_code, bom.material_name, bom.pm_code, mater.plm_id, bom.graph_no paintCode, bom.is_top " +
            " FROM tb_import_erp_bom bom " +
            " LEFT JOIN tb_import_erp_mater mater ON mater.material_code = bom.material_code  and  mater.erp_order_id = bom.erp_order_id " +
            " where bom.material_code not like '010%' and bom.material_code not like '020%'  and bom.material_code not like '050%' " +
            " and bom.status_id <> 'R' " +
            " and bom.erp_order_id = #{erpOrderId} " +
            " and bom.deleted = 0 " +
            " order by bom.graph_no ")
    List<OrderExternalBomResVo> treeList(@Param("erpOrderId") Integer erpOrderId);

    @Select(" SELECT DISTINCT bom.*, bom.graph_no paintCode" +
            " FROM tb_import_erp_bom bom " +
            " LEFT JOIN tb_import_erp_mater mater ON mater.material_code = bom.material_code and  mater.erp_order_id = bom.erp_order_id" +
            " where bom.material_code not like '010%' and bom.material_code not like '020%'  and bom.material_code not like '050%' and bom.material_code not like '060%'  " +
            " and bom.status_id <> 'R' " +
            " and bom.erp_order_id = #{erpOrderId} " +
            " and bom.deleted = 0 " +
            " order by bom.graph_no ")
    List<ImportErpBom> tree(@Param("erpOrderId") Integer erpOrderId);


    @Select(" SELECT DISTINCT bom.*, bom.graph_no paintCode" +
            " FROM tb_import_erp_bom bom " +
            " LEFT JOIN tb_import_erp_mater mater ON mater.material_code = bom.material_code and  mater.erp_order_id = bom.erp_order_id" +
            " where bom.status_id <> 'R' " +
            " and bom.erp_order_id = #{erpOrderId} " +
            " and bom.deleted = 0 " +
            " order by bom.graph_no ")
    List<ImportErpBom> treeAll(@Param("erpOrderId") Integer erpOrderId);

    @Select(" delete from tb_import_erp_bom where id = #{id}")
    void realDelete(@Param("id") Integer id);
}
